package com.ryskoo.catering.employeetablerel.service;

import com.ryskoo.catering.employeetablerel.domain.EmployeeTableRelPO;
import com.ryskoo.catering.employeetablerel.repository.IEmployeeTableRelRepository;
import com.ryskoo.framework.core.service.BasicServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import java.util.List;

@Service
@Transactional
public class EmployeeTableRelServiceImpl extends BasicServiceImpl<EmployeeTableRelPO> implements IEmployeeTableRelService{
    @Autowired
    private IEmployeeTableRelRepository employeeTableRelRepository;

    @PostConstruct
    public void init() {
        this.setDao(employeeTableRelRepository);
    }

    @Override
    public EmployeeTableRelPO getByEmployeeAndTable(String employeeUuid, String tableUuid) {
        return employeeTableRelRepository.getByEmployeeAndTable(employeeUuid,tableUuid);
    }

    @Override
    public void updateState(String employeeUuid, String tableUuid, boolean state) {
        EmployeeTableRelPO po = employeeTableRelRepository.getByEmployeeAndTable(employeeUuid,tableUuid);
        if(null!=po){
            po.setState(state);
            employeeTableRelRepository.update(po);
        }else{
            po = new EmployeeTableRelPO();
            po.setEmployeeUuid(employeeUuid);
            po.setTableUuid(tableUuid);
            po.setState(state);
            employeeTableRelRepository.create(po);
        }
    }

    /**
     * 根据台桌uuid查询关联的服务员uuid集合
     *
     * @param tableUuid
     * @return
     */
    @Override
    public List<String> getEmpUuids(String tableUuid) {
        return employeeTableRelRepository.getEmpUuids(tableUuid);
    }
}
